package org.fuys.coder.application.admin;

import org.fuys.coder.common.entity.Result;
import org.fuys.coder.common.util.JWTUtil;
import org.fuys.coder.domain.auth.service.vertify.permission.repo.IPermissionRepoServiceAggregation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @projectName: fuys-low-coder
 * @package: org.fuys.coder.application.admin
 * @className: AdminAuthController
 * @author: WangJing
 * @description: 用于验证操作 一般是对于进入管理页面的请求 以及 对重要操作的确定操作进行鉴权
 * @date: 2024/7/11 23:12
 * @version: 1.0
 */
@RestController
@RequestMapping("/fuyscoder/admin")
public class AdminAuthController {

    @Resource
    private IPermissionRepoServiceAggregation permissionRepoServiceAggregation;

    @GetMapping("/check")
    public Result checkRequest(HttpServletRequest request){
        try {
            if (permissionRepoServiceAggregation.checkAuth(JWTUtil.getUserId(request))) {
                return Result.ok();
            }else{
                return Result.error("无权进入");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("出现异常 认证失败");
        }
    }
}
